//
//  MPBTools+SystemPrivacy.m
//  MiaoPai
//
//  Created by jiaxuzhou on 2017/6/10.
//  Copyright © 2017年 Jeakin. All rights reserved.
//
//


#import "MPBTools+SystemPrivacy.h"
#import "MPTAuthorizationNotificationTools.h"
#import "MPTAuthorizationMicrophoneTools.h"
#import "MPTAuthorizationCameraTools.h"
#import "MPTAuthorizationPhotoTools.h"
#import "MPTAuthorizationContactsTools.h"
#import "MPTAuthorizationLocationTools.h"
#import "MPTAuthorizationMicrophoneTools.h"


@implementation MPBTools (SystemPrivacy)


- (MPE_AuthorizationStatus)getAuthorizationStatusWithType:(MPE_AuthorizationType)type
                                                    param:(id)paramNeed
{
    switch (type)
    {
        case MPE_AuthorizationNotification:
        {
           return [[MPTAuthorizationNotificationTools sharedInstance] authorizationStatus];
        }
            break;
        case MPE_AuthorizationCamera:
        {
            return [[MPTAuthorizationCameraTools sharedInstance] authorizationStatus];
        }
            break;
        case MPE_AuthorizationPhotos:
        {
            return [[MPTAuthorizationPhotoTools sharedInstance] authorizationStatus];
        }
            break;
        case MPE_AuthorizationContacts:
        {
            return [[MPTAuthorizationContactsTools sharedInstance] authorizationStatus];
        }
            break;
        case MPE_AuthorizationLocation:
        {
            return [[MPTAuthorizationLocationTools sharedInstance] authorizationStatus];
        }
            break;

  
        case MPE_AuthorizationMicrophone:
        {
            return [[MPTAuthorizationMicrophoneTools sharedInstance] authorizationStatus];
        }
            break;
        default:
            
            return MPE_AuthorizationDenied;
            break;
    }
    
    return MPE_AuthorizationDenied;
}

- (void)authorizeWithType:(MPE_AuthorizationType)type
                    param:(id)paramNeed
                  resault:(AuthorizationHandler)completion
                 backData:(AuthorizationResaultData)backData
{
    switch (type)
    {
        case MPE_AuthorizationNotification:
        {
            MPTAuthorizationNotificationTools *tools = [MPTAuthorizationNotificationTools sharedInstance];
            
            if ([paramNeed isKindOfClass:[NSArray class]])
            {
                NSArray *aryParam = paramNeed;
                
                for (NSInteger i = 0; i<aryParam.count; i++)
                {
                    if (aryParam.count >1)
                    {
                        break;
                    }
                    
                    id paramFirst = aryParam[i];
                    
                    if ([paramFirst isMemberOfClass:[UIUserNotificationSettings class]])
                    {
                        tools.userNotificationSettings = paramFirst;
                    }
                    else if ([paramFirst isMemberOfClass:[NSNumber class]])
                    {
                        tools.remoteNotificationType = [(NSNumber *)paramFirst integerValue];
                    }
                }
            }
            
            [tools authorize:^(NSString * _Nullable deviceID, NSError * _Nullable error)
             {
                if (deviceID)
                {
                    if (completion)
                    {
                        completion(MPE_AuthorizationAuthorized,nil);
                    }
                    
                    if (backData)
                    {
                        backData(deviceID);
                    }
                }
                 else
                 {
                     if (completion)
                     {
                         completion(MPE_AuthorizationDenied,error);
                     }
                 }
            }];
        }
            break;
        case MPE_AuthorizationCamera:
        {
            [[MPTAuthorizationCameraTools sharedInstance] authorize:completion];
        }
            break;
        case MPE_AuthorizationPhotos:
        {
            [[MPTAuthorizationPhotoTools sharedInstance] authorize:completion];
        }
            break;
        case MPE_AuthorizationContacts:
        {
            [[MPTAuthorizationContactsTools sharedInstance] authorize:completion];
        }
            break;
        case MPE_AuthorizationLocation:
        {
            [[MPTAuthorizationLocationTools sharedInstance] authorize:completion];
        }
            break;


        case MPE_AuthorizationMicrophone:
        {
            [[MPTAuthorizationMicrophoneTools sharedInstance] authorize:completion];
        }
            break;
        default:
            break;
    }
}


@end
